<template>
  <div id="back">
    <div id = "container" >
      <h3>{{object.identity}}登录</h3>
      用户名:<input type="text" v-model="object.name" placeholder="请输入用户名" />
      <br><br>
      密码:<input type="password" v-model="object.password" />
      <br><br>
      <button @click="login()">登录</button>
      <br><br>
      <router-link to='/ChangePwd'>
        <span style="text-align:center;font-size: 14px; color:red;">修改密码</span>
      </router-link>
    </div>
  </div>
</template>

<script>
  // import Cookies from 'js-cookie';
  export default {
    data() {
      return {
        object:{
          name : '',
          identity:this.$route.query.source,
          password : ''
        },
      }
    },
    created(){
      this.tableHeight = window.innerHeight-500
    },
  methods: {
    login() {
      //首先根据identity来确定身份（用户/护工/管理员）并找到对应的表
      //先检查name是否存在，返回一个bool值
      if(this.object.name===this.object.password){
        alert("这个用户不存在哦！")
      }
      // 通过name 获得 password2,然后比较
      else if(this.object.password !== '123'){
        alert("密码错啦！")
      }
      else{
        if(this.object.identity=="用户"){
          let retu_user = JSON.stringify({
            name:this.object.name,
            password : this.object.password,
            identity : this.object.identity,
          })
          this.$router.push({path:'/components/User/user',query:{obj:retu_user}});
        }
        if(this.object.identity=="护工"){
          let retu_nurse = JSON.stringify({
            name:this.object.name,
            password : this.object.password,
            identity : this.object.identity,
            //list里面需要放绑定的老人的id、姓名、护理等级
            list:[{name:'zhang111111',age:'11'},{name:'li',age:'12'}]
          })
          this.$router.push({path:'/components/Nurse/nurse',query:{obj:retu_nurse}});
        }
      }
    }

  },

  mounted:function (){
      if(this.$route.query.obj){
        let hh = JSON.parse(this.$route.query.obj);
        this.object.name = hh.username;
        this.object.password = hh.password
      }

  }
}
</script>
<style scoped>
#container{
  background-color : #FFFFFF;
  width : 20%;
  height : auto;
  margin-left: 40%;
  margin-top: 200px;
  border-radius: 20px;
}
#back{
  /*background:url("http://cdn-dlut.supwisdom.com/student/static/common-home/img/theme1.jpg");*/
  background: url("../assets/background_login.jpg");
  width: 100%;
  height: 100%; /**宽高100%是为了图片铺满屏幕 */
  z-index: -1;
  position: fixed;
  top: 0px; /*这里是设置与顶部的距离*/
  left: 0px; /*这里是设置与左边的距离*/
  bottom: 0px;
  right: 0px;

}


</style>